package com.idbk.chargestation.activity.charge;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;

import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.MarkerOptions;
import com.idbk.chargestation.R;
import com.idbk.chargestation.amap.base.BaseMapViewActivity;
import com.idbk.chargestation.bean.JsonPoint;
import com.idbk.chargestation.bll.pile.PileVendors;

/**
 * 在地图上 显示单个充电点
 * @author lupc, zhx
 *
 */
public class ActivityCurrentPointInMap extends BaseMapViewActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_current_point_in_map);

		setupView(savedInstanceState);

		setupData();
	}

	private void setupView(Bundle savedInstanceState){
		setupToolBar2();
		initMapView(savedInstanceState);
	}

	private void setupData(){
		JsonPoint point = getIntent().getParcelableExtra(JsonPoint.KEY);
		if(point != null){
			aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(point.lat, point.lng), 14));
			
			PileVendors vendors = new PileVendors(this);
			Bitmap bmp = BitmapFactory
					.decodeResource(getResources(),vendors.getMarkerIcon(point.operatorId));
			BitmapDescriptor b = BitmapDescriptorFactory.fromBitmap(bmp);

			//创建option对象，并初始化相关属性
			MarkerOptions markerOption = new MarkerOptions()
			.position(new LatLng(point.lat, point.lng))
			.draggable(false)
			.title(point.name)			
			.icon(b);
			aMap.addMarker(markerOption);
		}
	}
}
